{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "907fdbb7-966f-46f1-adde-d9dc602b1f08",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入非负整数n： 3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  for循环：3! = 6\n",
      "while循环：3! = 6\n"
     ]
    }
   ],
   "source": [
    "fac = 1\n",
    "n = -1\n",
    "while (n < 0):\n",
    "    n=int(input(\"请输入非负整数n：\"))\n",
    "# 方法一：for循环\n",
    "for i in range(1, n+1): fac *= i\n",
    "print(str.format(\"  for循环：{0}! = {1}\", n, fac))\n",
    "# 方法二：while循环\n",
    "i = 1; fac = 1\n",
    "while (i <= n):\n",
    "    fac *= i; i+=1\n",
    "print(str.format(\"while循环：{0}! = {1}\", n, fac))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf25b79f-f9c1-437e-8faf-5203a2dc125e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
